#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 1e6 + 10, INF = 0x3f3f3f3f;

void solve()
{
    ll n;
    while (cin >> n) {
        map<string, ll> hs;
        for (ll i = 1;i <= n;i++) {
            string s;cin >> s;
            ll len = s.length();s = " " + s;

            vector<ll> ne(len + 10);
            for (ll i = 2, j = 0;i <= len;i++) {
                while (j && s[i] != s[j + 1]) j = ne[j];
                if (s[i] == s[j + 1]) j++;
                ne[i] = j;
            }
            ll xh = len - ne[len];
            // cout << xh << '\n';
            if (len % xh == 0) {
                hs[s.substr(1, xh)]++;
            } else {
                hs[s.substr(1, len)]++;
            }

        }

        ll ans = 0;
        for (auto [_, cnt] : hs) {
            ans += cnt * (cnt - 1) / 2;
        }
        cout << ans << '\n';
    }
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}